'''绘制节点的属性分布,并提供结果的输出或文件保存'''
import matplotlib.pyplot as plt
def plotnodes(graph,attribution):
    '''绘制图中节点属性的统计结果(附加:尝试matplotlib、seaborn等对应绘图库的文件输出,
    尤其是矢量图eps等格式的输出'''
    dic={}#创建该属性的字典
    for i in list(graph.nodes):
        if graph.nodes[i][attribution] not in dic.keys():
            dic[graph.nodes[i][attribution]]=1
        else:
            dic[graph.nodes[i][attribution]]=dic[graph.nodes[i][attribution]]+1
    for i in dic.keys():
        dic[i]=dic[i]/len(list(graph.nodes()))
    x=list(dic.keys())
    y=list(dic.values())
    plt.xlabel(attribution)
    plt.ylabel("pro of"+attribution)
    if len(x)>10:
        k=plt.plot(x,y,color='dodgerblue',linestyle='-',marker=',')
    else:
        k=plt.bar(x,y)
        #plt.text(x+k.get_width()/2,k.get_height(),'%d'%int(k.get_height()),ha='center',va='bottom')
    plt.show()
    plt.savefig(attribution+'.svg',dpi=600,format='svg')#保存为矢量图
